package com.zch.spring_demo.work.util;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author biscuit
 * @data 2018/01/17
 * 定时任务类
 */
@Component
public class SchedulerTask {
    private int count=0;
    /**(秒 分 时 日 月 周  年[可省略] )*/
    @Scheduled(cron = "*/3 * * * * ?")
    private void process(){
        System.out.println("this is scheduler task runing  "+(count++));
    }

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    /**每隔6秒就执行*/
    @Scheduled(fixedRate = 6000)
    public void reportCurrentTime() {
        System.out.println("现在时间：" + dateFormat.format(new Date()));
    }
}
